import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)


const store = new Vuex.Store({
	state: {
		// userInfo: '11',
		font:localStorage.getItem('font')||30,
		userInfo: JSON.parse(localStorage.getItem('userInfo'))?JSON.parse(localStorage.getItem('userInfo')) :'',
		bread: JSON.parse(sessionStorage.getItem('bread')) ? JSON.parse(sessionStorage.getItem('bread')) : [],
		pageParams:JSON.parse(sessionStorage.getItem('pageParams')) ? JSON.parse(sessionStorage.getItem('pageParams')) : [],
		carTypeParams:JSON.parse(sessionStorage.getItem('carTypeParams')) ? JSON.parse(sessionStorage.getItem('carTypeParams')) : [],
		setLanguage: '',
	},
	mutations: {
		ADD_FONT(state, val) {
			state.font = val;
			localStorage.setItem('font', val)
		},
		ADD_USER(state, val) {
			state.userInfo = val;
			localStorage.setItem('userInfo', JSON.stringify(val))
		},
		ADD_BREAD(state, val) {
			state.bread = val;
			sessionStorage.setItem('bread', JSON.stringify(val))
		},
		DELALL_BREAD(state, val) {
			state.bread = [];
			sessionStorage.setItem('bread', JSON.stringify([]))
		},
		DEL_BREAD(state, index) {
			let arr = state.bread.filter(item => item.path !== index);
			state.bread = arr;
		    sessionStorage.setItem('bread', JSON.stringify(arr))
		},
		ADD_PAGEPARAMS(state, val) {
			state.pageParams = val;
			sessionStorage.setItem('pageParams', JSON.stringify(val))
		},
		ADD_CARTYPEPARAMS(state, val) {
			state.carTypeParams = val;
			sessionStorage.setItem('carTypeParams', JSON.stringify(val))
		},
		
	},
	getters: {
		language: state => state.setLanguage
	}
})




export default store;
